// ml:run = $bin < input
#include <iostream>
#include <cstring>

using ll = long long;
int const maxn = 100007;
int const maxm = 256;
ll f[maxn][300];
ll count[maxn][300];
int a[maxn];
int n;

int prev(int x)
{
    return (x - 1 + maxm) % maxm;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin >> n;
    std::memset(f, -1, sizeof(f));
    for (int i = 1; i <= n; i++)
        std::cin >> std::hex >> a[i];
    f[1][0] = a[1]; count[1][0] = 1;
    f[1][maxm - 1] = 0; count[1][maxm - 1] = 0;
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < maxm; j++) {
            if (f[i - 1][j] != -1) {
                f[i][j] = f[i - 1][j];
                count[i][j] = count[i - 1][j];
            }
            if (f[i - 1][prev(j)] != -1 && f[i - 1][prev(j)] + (count[i - 1][prev(j)] ^ a[i]) > f[i][j]) {
                f[i][j] = f[i - 1][prev(j)] + (count[i - 1][prev(j)] ^ a[i]);
                count[i][j] = count[i - 1][prev(j)] + 1;
            }
        }
    }
    ll max = 0;
    for (int i = 0; i < maxm; i++) {
        max = std::max(max, f[n][i]);
    }
    std::cout << max << "\n";
}

